#include <iostream>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
 
using namespace std;
typedef long long ll;
const int N = 100005;
char s[N], t[N];


int fail[N];
int kmp(char* str, char* pat, int len){
	int i, j, k;
	 memset(fail, -1, sizeof(fail));
	for (i = 1; pat[i]; ++i) {
		 for (k=fail[i-1]; k>=0 && pat[i]!=pat[k+1];
		 k=fail[k]);
		 if (pat[k + 1] == pat[i]) fail[i] = k + 1;
	 }
	i = j = 0;
	while( str[i] && pat[j] ){
		if(i == len-1 && j==0){
			return -1;
		}
		if( pat[j] == str[i] ){
			i = (i+1)%len;
			j = (j+1)%len;
		}
		else if(j == 0)
			++i;
		else
		 	j = fail[j-1]+1; 
	}
	if( pat[j] ) return -1;
	 else return i-j;
} 
 
int main() {
    int T;
    scanf("%d", &T);
    while(T--){
		scanf("%s", s);
		scanf("%s", t);
		int len = strlen(s);
		if(kmp(s, t, len)==-1){
			printf("No\n");
		}else{
			printf("Yes\n");
		}
	}
    return 0;
}
